package ${basepackage}.framework.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import ${basepackage}.framework.base.dao.BaseHibernateDao;
import ${basepackage}.framework.base.page.Page;
import ${basepackage}.framework.model.AuditLog;
import ${basepackage}.framework.query.AuditLogQuery;



@Repository("auditLogDAO")
/**
 * @author Xi Wei
 * @version 1.0
 * @since 1.0
 */
 public class AuditLogDAOImpl extends BaseHibernateDao<AuditLog, Long> implements
		AuditLogDAO {


	@Override
	public Class getEntityClass() {
		// TODO Auto-generated method stub
		return AuditLog.class;
	}
	
	
	
	public AuditLog getPreviousAuditLog(AuditLog auditLog) {
		
		AuditLogQuery query = new AuditLogQuery();
		query.setEntityName(auditLog.getEntityName());
		query.setAuditLogId(auditLog.getAuditLogId());
		query.setSortColumns("auditLogId DESC");
		query.setPageSize(1);
		

		
		String sql = "select t from AuditLog t where 1=1 "
				+ "/~ and t.entityName = {entityName} ~/"
				+"/~ and t.auditLogId < {auditLogId} ~/";
		
		
		Page<AuditLog> page =  pageQuery(sql, query);
		
		List<AuditLog> result = page.getResult();
		if(result != null && !result.isEmpty()){
			return result.get(0); 
		}
		return null;
	}

}
